#include<iostream>

using namespace std;

void solve()
{
    int n, k; cin >> n >> k;
    int num = 0;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int temp; cin >> temp;
        if (temp >= k) num += temp;
        else if (num && !temp)
        {
            num -= 1;
            ans += 1;
        }
    }
    cout << ans << endl;
    return;
}

int main()
{
    int t; cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}